import {
	defineStore
} from 'pinia'

import {
	ref
} from 'vue'
export let userStore = defineStore("user", () => {
	// 定于状态变量
	// 定义token令牌
	let token = ref("")
	// 已登录用户信息
	
	let userInfo = ref({})
	let isLogin = ref(false)
	let currentPos = ref({
		latitude: 0,
		longitude: 0
	})
	let hasPos = ref(false)

	function addUserInfo(id, username,  mobile) {
		//自行添加内容
		this.userInfo.id = id
		this.userInfo.username = username;
		
		this.userInfo.mobile = mobile;
		
		this.isLogin = true
	}
	// 清除用户登录状态
	function clearUserInfo() {
		//自行添加内容
		this.userInfo = {}
		this.isLogin = false
		this.token = ""
	}

	function setPos(latitude, longitude) {
		currentPos.value.latitude = latitude
		currentPos.value.longitude = longitude
		hasPos.value = true

	}


	return {
		
		userInfo,
		isLogin,
		addUserInfo,
		clearUserInfo,
		setPos,
		currentPos,
		hasPos
	}
})